package com.article.utils;


import com.article.model.MenuInfo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;

import java.util.List;

public class Authority {
    /**
     * 判断是否有该权限
     *
     * @param url
     * @return
     */
    public static boolean hasAuthority(String url) {
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        List<MenuInfo> menuInfos = (List<MenuInfo>) session.getAttribute("Auths"); // 获取菜单列表

        for (MenuInfo auth : menuInfos) {
            // System.out.println(auth);
            if (auth.getMenuUrl().equals(url) && auth.isHasMenu()) {
                return true;
            }
        }
        return false;
    }
}
